<link type="text/css" href="/admins/js/jquery/css/ui-lightness/jquery-ui-1.8.20.custom.css" rel="stylesheet" />
<script type="text/javascript" src="/admins/js/My97DatePicker/WdatePicker.js"></script>
<div class="admin_nrtop">
    <div class="ad_search">
        <form action="/admini/manageuser/coupon/"  method="post" style="margin:0px" id="form1">
        <div class="search">
            <div class="soubox">
                <input type="text" id="quick" name="quick" value="<?php echo $this->quick?$this->quick:"";?>" placeholder="输入优惠券序号/用户信息/批次号等"/>
                <input type="hidden" id="timescope" name="timescope" value="<?php echo $this->timescope?$this->timescope:"dateCreated";?>" />
                <input type="hidden" id="starttime" name="starttime" value="<?php echo $this->starttime?$this->starttime:"";?>"/>
                <input type="hidden" id="endtime" name="endtime" value="<?php echo $this->endtime?$this->endtime:"";?>" />
                <input type="hidden" id="pagesize" name="pagesize" value="<?php echo $this->pagesize?$this->pagesize:15;?>" />
                <input type="hidden" id="selType" name="selType" value="<?php echo $this->selType?$this->selType:"";?>" />
                <input type="hidden" id="scope" name="scope" value="<?php echo $this->scope?$this->scope:"";?>" />
                <input type="hidden" id="status" name="status" value="<?php echo $this->status?$this->status:"";?>" />
                <input type="hidden" id="batchNo" name="batchNo" value="<?php echo $this->batchNo?$this->batchNo:"";?>" />
            </div>
            <a href="javascript:$('#form1').submit();"><span>搜索</span></a>
        </div>

        <div class="timebox">
            <div class="ad_time">
                <div class="timezdy">
                    <div class="timeselect2">
                        <span><?php if($this->timescope){
                                switch ($this->timescope) {
                                    case "dateCreated":
                                        echo "创建时间";
                                        break;
                                    case "startTime":
                                        echo "开始时间";
                                        break;
                                    case "dateExpired":
                                        echo "结束时间";
                                        break;
                                    case "useTime":
                                        echo "使用时间";
                                        break;
                                    default:
                                        echo "范围选择";
                                        break;
                                }
                            }else{echo "创建时间";}?>
                        </span><i></i>
                    </div>
                    <div class="timeslelct_xl" style="display:none;">
                        <ul>
                            <li><a href="javascript:void(0)" name="dateCreated" class="setSel" i="timescope">创建时间</a></li>
                            <li><a href="javascript:void(0)" name="startTime" class="setSel" i="timescope">开始时间</a></li>
                            <li><a href="javascript:void(0)" name="dateExpired" class="setSel" i="timescope">结束时间</a></li>
                            <li><a href="javascript:void(0)" name="useTime" class="setSel" i="timescope">使用时间</a></li>
                        </ul>
                    </div>
                </div>
                <div class="timefw">
                    <div class="time">
                        <!--点击后悬停样式为：<div class="timeselect t_on">-->
                        <div class="timeselect"  id="stime">
                            <span id="stimeval"><?php echo $this->starttime?$this->starttime:date("Y-m-d",mktime(0,0,0,date("m"),date("d")-90,date("Y")));?></span><i></i>
                        </div>
                        <div class="timeslelctbox">
                            <!---时间插件放此DIV-->
                        </div>
                    </div>
                    <div class="timezhi">
                        <span>至</span>
                    </div>
                    <div class="time" >
                        <div class="timeselect" id="etime">
                            <span id="etimeval"><?php echo $this->endtime?$this->endtime:date("Y-m-d");?></span><i></i>
                        </div>
                        <div class="timeslelctbox">
                            <!---时间插件放此DIV-->
                        </div>
                    </div>
                </div>
            </div>
            <div class="timeok">
                <a href="javascript:$('#form1').submit();">确定</a>
            </div>
        </div>
        <div class="xianshi">
            <label>显示：</label>
            <ul>
                <li <?php echo $this->pagesize?($this->pagesize==15?'class="xson"':""):'class="xson"'; ?>><a href="javascript:void(0)" name="15" class="setSel" i="pagesize">15</a></li>
                <li <?php echo $this->pagesize?($this->pagesize==30?'class="xson"':""):""; ?>><a href="javascript:void(0)" name="30" class="setSel" i="pagesize">30</a></li>
                <li <?php echo $this->pagesize?($this->pagesize==45?'class="xson"':""):""; ?>><a href="javascript:void(0)" name="45" class="setSel" i="pagesize">45</a></li>
            </ul>
        </div>
        </form>
    </div>
</div>
<div  class="biaoge">
    <div class="biaotbody">
        <table>
            <tr>
            	<th class="li4">
                    <div class="lileft"><input name="checkall" type="checkbox" id="checkall" value=""> 全选</div>
                </th>

                <th class="li15">
                    <div class="lileft"><span>优惠券名称/序号</span></div>
                </th>
                <th class="li5">
                    <div class="lileft"><span>使用密码</span></div>
                </th>
                <th class="li9">
                    <div class="lileft"><span>创建时间/使用时间</span></div>
                </th>
                <th class="li9">
                    <div class="lileft"><span>开始时间/结束时间</span></div>
                </th>
                <th class="li7">
                    <div class="biaoxiala">
                        <div class="lixiala">
                            <span>类型</span>
                            <i></i>
                        </div>
                        <div class="biaoxllb" style="display:none;">
                            <ul>
                                <?php if($this->couponTypeAll){ foreach ($this->couponTypeAll as $typeKey => $typeVal) { ?>
                                    <li><a href="javascript:void(0)" name="<?php echo $typeKey;?>" class="setSel" i="selType"><?php echo $typeVal; ?></a></li>
                                <?php }} ?>
                            </ul>
                        </div>
                    </div>
                </th>
                <th class="li4">
                    <div class="lileft"><span>底线金额</span></div>
                </th>
                <th class="li4">
                    <div class="lileft"><span>折扣金额</span></div>
                </th>
                <th class="li9">
                    <div class="lileft"><span>用户信息</span></div>
                </th>
                <th class="li7">
                    <div class="biaoxiala">
                        <div class="lixiala">
                            <span>使用范围</span>
                            <i></i>
                        </div>
                        <div class="biaoxllb" style="display:none;">
                            <ul>
                                <?php if($this->arrscope){ foreach ($this->arrscope as $scopeKey => $scopeVal) { ?>
                                    <li><a href="javascript:void(0)" name="<?php echo $scopeKey;?>" class="setSel" i="scope"><?php echo $scopeVal; ?></a></li>
                                <?php }} ?>
                            </ul>
                        </div>
                    </div>
                </th>
                <th class="li9">
                    <div class="biaoxiala">
                        <div class="lixiala">
                            <span>批次序号</span>
                            <i></i>
                        </div>
                        <div class="biaoxllb" style="display:none;width: 200px;">
                            <ul>
                                <?php if($this->batchAll){ foreach ($this->batchAll as  $batchVal) { ?>
                                <li><a href="javascript:void(0)" name="<?php echo $batchVal->No;?>" class="setSel" i="batchNo" style="width:180px;"><?php echo $batchVal->Name; ?></a></li>
                                <?php }} ?>
                            </ul>
                        </div>
                    </div>
                </th>
                <th class="li5">
                    <div class="biaoxiala">
                        <div class="lixiala">
                            <span>状态</span>
                            <i></i>
                        </div>
                        <div class="biaoxllb" style="display:none;width: 92px;">
                            <ul>
                                <?php if($this->couponStatusAll){ foreach ($this->couponStatusAll as $statusKey => $statusVal) { ?>
                                    <li><a href="javascript:void(0)" name="<?php echo $statusKey;?>" class="setSel" i="status"><?php echo $statusVal; ?></a></li>
                                <?php }} ?> 
                            </ul>
                        </div>
                    </div>
                </th>
            </tr>
        </table>
    </div>
    <?php if($this->selType || $this->status || $this->scope || $this->batchNo){?>
        <div class="xzinfo">
          <ul>
              <?php if($this->selType){ ?><li><div class="xzinfobox"><span><?php echo $this->couponTypeAll[$this->selType];?></span><a href="javascript:void(0)" class="removeOp" title="撤销" name="selType"><i>撤销</i></a></div></li><?php }?>
              <?php if($this->scope){ ?><li><div class="xzinfobox"><span><?php echo $this->arrscope[$this->scope];?></span><a href="javascript:void(0)" class="removeOp" title="撤销" name="scope"><i>撤销</i></a></div></li><?php }?>
              <?php if($this->batchItem){ ?><li><div class="xzinfobox"><span><?php echo $this->batchItem->Name;?></span><a href="javascript:void(0)" class="removeOp" title="撤销" name="batchNo"><i>撤销</i></a></div></li><?php }?>
              <?php if($this->status){ ?><li><div class="xzinfobox"><span><?php echo $this->couponStatusAll[$this->status];?></span><a href="javascript:void(0)" class="removeOp" title="撤销" name="status"><i>撤销</i></a></div></li><?php }?>
          </ul>
        </div>
     <?php }?>
     <div class="table">
         <table>
             <?php if($this->couponlist){
                 foreach ($this->couponlist as $Item) { 
				 	if($Item->id){
				 ?> 
                 
                 <tr>
                 
      				<td class="li4">
                         <div class="lileft"><input type="checkbox" value="<?php echo $Item->id;?>" class="checkbox-del" name='checkbox'  /></div>
                     </td>
                     
                     <td class="li15">
                         <div class="lileft"><?php echo $Item->Name."<br>".$Item->No;?></div>
                     </td>
                     <td class="li5">
                         <div class="lileft">
                             <?php echo $Item->Password;?>
                        </div>
                     </td>
                     <td class="li9">
                         <div class="lileft">
                             <?php echo $Item->DateCreated."<br>".$Item->useTime;?>
                        </div>
                     </td>
                     <td class="li9">
                         <div class="lileft">
                             <?php echo $Item->StartTime."<br>".$Item->DateExpired;?>
                        </div>
                     </td>
                     <td class="li7">
                         <div class="lileft"><?php echo $Item->typeName;?></div>
                     </td>
                     <td class="li4">
                         <div class="lileft">
                             <?php echo $Item->money;?>
                        </div>
                     </td>
                     <td class="li4">
                         <div class="lileft">
                             <?php echo $Item->discount;?>
                        </div>
                     </td>
                     <td class="li9">
                         <div class="lileft">
                             <a href="/admini/manageuser/userdetail/id/<?php echo $Item->UserId;?>" class="indexa" target="_blank"><?php echo $Item->user->nikename."<br>".$Item->user->storeno;?></a>
                        </div>
                     </td>
                     <td class="li7">
                         <div class="lileft">
                             <?php echo $Item->scopeName;?>
                        </div>
                     </td>
                     <td class="li9">
                         <div class="lileft">
                             <?php echo $Item->batchNo;?>
                        </div>
                     </td>
                     <td class="li5">
                         <div class="lileft">
                             <?php echo $Item->statusName;?>
                        </div>
                     </td>
                 </tr>
             <?php }}  } else {
                echo "<font size='4' color='red'>暂无数据</font>";
                }?>   
         </table>
     </div>
 </div>
<div class="toolbar">
    <div class="qunx">
        <ul>
            <li><a class="anvbotton" href="/admini/manageuser/addcoupon" ><span>添加优惠券</span></a></li>
            <li><a class="anvbotton" href="/admini/manageuser/couponbatch" style="margin-left:10px"><span>优惠券批次</span></a></li>
            <li><a class="anvbotton" href="/admini/manageuser/delcoupon" id="del-button" style="margin-left:10px"><span>删除优惠券</span></a></li>
        </ul>
    </div>
<?php
    echo $this->partial('paging.phtml', array("pages" => $this->couponall,"pamas"=>"quick=$this->quick&timescope=$this->timescope&starttime=$this->starttime&endtime=$this->endtime&pagesize=$this->pagesize&selType=$this->selType&scope=$this->scope&status=$this->status&batchNo=$this->batchNo"));        
?>
</div>
<script>
    $(function(){
        $("#stime").click(function(){
            $(this).attr("class","timeselect t_on");
            WdatePicker({el:'stimeval',vel:'starttime',onpicked:function(){
                    $("#stime,#etime").attr("class","timeselect");
                    $(".soubox #timescope").val("");
            }});
        });
        $("#etime").click(function(){
            $(this).attr("class","timeselect t_on");
            WdatePicker({el:'etimeval',vel:'endtime',onpicked:function(){
                    $("#stime,#etime").attr("class","timeselect");
                    $(".soubox #timescope").val("");
            }});
        });
        $(".timezdy").click(function(){
            $(".timezdy .timeselect2").attr("class","timeselect2 timeon");
            $(".timeslelct_xl").show();
        });
        $(".timezdy").mouseleave(function(){
           $(".timeselect2").attr("class","timeselect2");
           $(".timeslelct_xl").hide();
        });
        $(".lixiala").click(function(){
            $(".lixiala").attr("class","lixiala");
            $(".lixiala").next("div").hide();

            $(this).attr("class","lixiala bton");
            $(this).next("div").show();
        });
        $(document).bind("click",function(e){
            var target  = $(e.target);
            if(target.closest(".biaoxiala").length == 0){
                $(".lixiala").attr("class","lixiala");
                $(".lixiala").next("div").hide();
            }
            if(target.closest("#stime").length == 0){
                $("#stime").attr("class","timeselect");
            }
            if(target.closest("#etime").length == 0){
                $("#etime").attr("class","timeselect");
            }
       });
       $(".setSel").click(function(){
          var selVal = $(this).attr("name");
          var selType = $(this).attr("i");
          $("#form1 #"+selType).val(selVal);
          $("#form1").submit();
       });
       $(".removeOp").click(function(){
          var option = $(this).attr("name");
          $("#form1 #"+option).val("");
          $("#form1").submit();
       });
       $("#addGeneralize").click(function(){
          location.href='/admini/generalize/addgeneralizd';
       });
	   
	   $("input[name='checkall']").click(function(){
       var ck = $("input[name='checkall']").attr("checked");
       if(ck == "checked"){
           $("input[name='checkbox']").attr("checked",true);
           $("input[name='checkbox'][disabled='true']").attr("checked",false);
       }else{
           $("input[name='checkbox']").attr("checked",false);
       }
    });
	//删除优惠券
	$('#del-button').click(function(){
         var idlist = '';
         $('input[name="checkbox"]:checked').each(function(){   
                var id = $(this).attr("value");
                id=id.replace(/[^\d]*/ig,"");
		idlist+= id+',';
		});
        if(idlist == ''){
            alert("请选择优惠券");
            return false;
        }else{
            if(confirm("您确定删该优惠券吗？","提示信息")){ 
                $.ajax({
                    type: 'POST',
                    url: '/admini/manageuser/delcoupon/idlist/'+idlist,
					dataType: "json",
                    success: function(data) {
                        if(data == 1){
                            alert("删除成功");
                        }else{
                            alert("发生未知错误，请重新操作");
                        }
                        location.href='http://admin1.uuch.com/admini/manageuser/coupon/';
                    }
                });
            }
        }
    });	   
    });
</script>